define(function(require, exports){
	var util = require('util');

	exports.onMain = function(controller, data, app){
		var cont = app.getContainer({
			scenes: 'login',
			full: false,
			sitelist: false,
			setup_btn: false,
			title: LANG('登录')
		});
		cont.addClass('appScenesLoginMain');

		var login = app.core.get('SYS_USER_LOGIN');
		if (!login){
			app.core.createAsync(
				'SYS_USER_LOGIN',
				'login/action/login.login',
				{
					'success': function(user){
						app.setUser(user);
						var cb = app.config('loginCb');
						if(cb && util.isFunc(cb)) {
							cb(app, function() {
								app.core.cast('sysUserLogin', user);
								controller.afterLogin();
							});
						}
					},
					'target': cont.getDOM()
				}
			);
		}else {
			login.reset().show();
		}
	};


	// 退出UC之后再退出产品
	exports.onLogout = function(controller, data, app){
		var cont = app.getContainer({
			'scenes':'logout',
			'title':LANG('退出账号')
		});
		cont.addClass('appScenesLoginMain');

		var mod = app.core.get('SYS_USER_LOGOUT');
		if (!mod){
			app.core.createAsync('SYS_USER_LOGOUT', 'login/action/login.logout', {
				'target': cont.getDOM()
			}, function(mod){
				mod.logout();
			});
		}else {
			mod.logout();
		}
	};

	// Admin入口
	exports.onAdmin = function(controller, data, app){
		var adminUrl = "/admin.html";
		var user = app.getUser();
		if(user && user.current && user.current.isAdmin){
			app.mc.send('/adminLogin', {userId: user.login.userId}, function(err, ticket){
				if(err){
					app.alert(err.message);
					app.controller.navigate(-1);
				}else{
					app.controller.navigate(adminUrl + "#ticket/chk/" + ticket);
				}
			});
		}
	};
});